// Mmanagement/modifyInforM/modifyInforM.js
const app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selects:[
      {id:0,name:'店主信息'},
      {id:1,name:'店员信息'},
      {id:2,name:'店铺基本信息'}
    ],
    selectvalue:'请选择',
    shidden:true,
    inptvalue:[],
    cindex:'play'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var shopnumber=wx.getStorageSync('shopnumber');
    that.setData({
      shopnumber
    })
  },
  // 选择框
  selectitem(e){
    var that=this;
    var selectvalue = e.currentTarget.dataset.value;
    var cindex=e.currentTarget.dataset.index;
    var shopnumber=that.data.shopnumber;
    this.setData({
      selectvalue,
      shidden:true,
      cindex
    })
    // 通过selectvalue发送请求
    // 判断selectvalue
    if(selectvalue == '店主信息'){
      app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php',{num:7,bname:'Mmshopkeeper',shopnumber}).then(res=>{
        that.setData({
          inptvalue:res
        })
      })
    }else if(selectvalue == '店员信息'){
      app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php',{num:7,bname:'Mmclerks',shopnumber}).then(res=>{
        that.setData({
          inptvalue:res
        })
      })
    }else if(selectvalue == '店铺基本信息'){
      app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php',{num:7,bname:'MmshopBinfors',shopnumber}).then(res=>{
        that.setData({
          inptvalue:res
        })
      })
    }

  },
  butstyle(){
    this.setData({
      shidden:false
    })
  },
  // 店主表单
  Mmshopkeeper(e){
    var bname='Mmshopkeeper';
    var itemid=e.target.dataset.itemid;
    var sname=e.detail.value.sname;
    var stelephone=e.detail.value.stelephone;
    var teleyz=/^1[3456789]\d{9}$/;
    if(sname!=''&&stelephone!=''){
      if(teleyz.test(stelephone)){
        app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php', {num:8,bname,itemid,sname,stelephone}).then(res=>{
          wx.showToast({
            title: res,
            icon:'none'
          })
        })
      }else{
        wx.showToast({
          title: '请输入正确的号码格式',
          icon:'none'
        })
      }
    }else{
      wx.showToast({
        title: '输入框不能为空',
        icon:'none'
      })
    }
  },
  // 店员表单
  Mmclerks(e){
    var bname='Mmclerks';
    var itemid=e.target.dataset.itemid;
    var cname=e.detail.value.cname;
    var ctelephone=e.detail.value.ctelephone;
    var teleyz=/^1[3456789]\d{9}$/;
    if(cname!=''&&ctelephone!=''){
      if(teleyz.test(ctelephone)){
        app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php', {num:9,bname,itemid,cname,ctelephone}).then(res=>{
          wx.showToast({
            title: res,
            icon:'none'
          })
        })
      }else{
        wx.showToast({
          title: '请输入正确的号码格式',
          icon:'none'
        })
      }
    }else{
      wx.showToast({
        title: '输入框不能为空',
        icon:'none'
      })
    }
  },
  // 店铺表单
  MmshopBinfors(e){
    var bname='MmshopBinfors';
    var itemid=e.target.dataset.itemid;
    var shopname=e.detail.value.shopname;
    var shoptype=e.detail.value.shoptype;
    if(shopname!=''&&shoptype!=''){
      app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php', {num:10,bname,itemid,shopname,shoptype}).then(res=>{
        wx.showToast({
          title: res,
          icon:'none'
        })
      })
    }else{
      wx.showToast({
        title: '输入框不能为空',
        icon:'none'
      })
    }
  },
  // 删除按钮
  delect(e){
    var bname=e.target.dataset.bname;
    var itemid=e.target.dataset.id;
    var shopnumber=this.data.shopnumber;
    app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php',{num:11,bname,itemid}).then(res=>{
        wx.showToast({
          title: res,
          icon:'none'
        })
        if(res="删除成功"){
          app.comrequest('https://ipass.cc/myapi/Mmanagement/MUloginxg.php',{num:7,bname,shopnumber}).then(res=>{
            this.setData({
              inptvalue:res
            })
          })
        }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})